<?php namespace Admin\Controller;

class SettingController extends CommonController{
	private $model;
	public function __init(){
		//调用CommonController里面的构造函数
		parent::__init();

		$this->model = new \Admin\Model\Setting;
	}
	
	//展示分类
	public function setindex(){
		//把数据变为树状结构
		$data = Data::tree(Db::table('category')->join('setting','cid','=','stcid')->get(),'cname');
		$setindex = $this->model->get();
		//分配数据
		View::with('setindex',$setindex);
		View::with('data',$data);

		if(IS_POST){

			if($this->model->store()) View::success('添加成功',U('setindex'));
			View::error($this->model->getError());
		}
		
		//载入模板
	    View::make();
	}
	
	public function setlist(){
		//		显示所属类型
		$model2 = new \Admin\Model\Type;
		$tempdata = $model2 ->join('category','type_tid','=','tid')->get();
		//把数据变为树状结构
		$data = Data::tree($tempdata,'cname');
		
		$setindex = Db::table('setting')->get();
		//分配数据
		View::with('setindex',$setindex);
		//分配数据
		View::with('data',$data);
		
		if(IS_POST){

			if($this->model->store()) View::success('添加成功',U('setindex'));
			View::error($this->model->getError());
		}
	 //载入模板
	    View::make();
	}
}









 ?>